<?php
/***********************************/
// World of Warcraft Armory SDK    //
// Licence: GNU GPLv3              //
// Author: Giacomo 'elegos' Furlan //
// File: wowasdk.shared.php        //
/***********************************/

define("EU","EU");
define("US","US");

define("FACTION_ALLIANCE",0);
define("FACTION_HORDE",1);

define("GENDER_MALE",0);
define("GENDER_FEMALE",1);

define("SECONDBAR_TYPE_MANA","m");
define("SECONDBAR_TYPE_RAGE","r");
define("SECONDBAR_TYPE_RUNIC","p");

define("BASESTAT_STRENGHT",0);
define("BASESTAT_AGILITY",1);
define("BASESTAT_STAMINA",2);
define("BASESTAT_INTELLECT",3);
define("BASESTAT_SPIRIT",4);
define("BASESTAT_ARMOR",5);

define("RESISTANCE_ARCANE",0);
define("RESISTANCE_FIRE",1);
define("RESISTANCE_FROST",2);
define("RESISTANCE_HOLY",3);
define("RESISTANCE_NATURE",4);
define("RESISTANCE_SHADOW",5);

define("SPELL_TYPE_ARCANE",0);
define("SPELL_TYPE_FIRE",1);
define("SPELL_TYPE_FROST",2);
define("SPELL_TYPE_HOLY",3);
define("SPELL_TYPE_NATURE",4);
define("SPELL_TYPE_SHADOW",5);
define("SPELL_TYPE_PET_BONUS",6);

define("RACE_HUMAN",		1);
define("RACE_ORC",			2);
define("RACE_DWARF",		3);
define("RACE_NIGHT_ELF",	4);
define("RACE_UNDEAD",		5);
define("RACE_TAUREN",		6);
define("RACE_GNOME",		7);
define("RACE_TROLL",		8);
define("RACE_BLOOD_ELF",	10);
define("RACE_DRAENEI",		11);

define("CLASS_WARRIOR",		1);
define("CLASS_PALADIN",		2);
define("CLASS_HUNTER",		3);
define("CLASS_ROGUE",		4);
define("CLASS_PRIEST",		5);
define("CLASS_DEATH_KNIGHT",6);
define("CLASS_SHAMAN",		7);
define("CLASS_MAGE",		8);
define("CLASS_WARLOCK",		9);
define("CLASS_UNKNOWN",		10); // maybe future hero class?
define("CLASS_DRUID",		11);

/**
  Downloads a file from the internet via curl.
  @param $url URL of the file
  @param $destination Where to save the file
  @param $cache_time Time (in seconds) the file should be cashed for before being downloaded again (default 3 days)
  @param $force_cache if set to true, $cache_time will be ignored and the file will be in any case dowloaded again (default false)
*/
function downloadFileViaCurl($url, $destination, $cache_time = 259200, $force_cache = false) {
	if(!function_exists("curl_init")) die("You need curl installed and enabled in your PHP installation!");

	if($force_cache === true
		|| !file_exists($destination)
		|| time() - filemtime($destination) > $cache_time ) {			
		$ch = curl_init();
		$useragent="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5;" .
           			" it; rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10";
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
		sleep(1); // WoW Armory Throttling Policy
		$file_stream = curl_exec($ch);
		curl_close($ch);
		$file = fopen($destination,'w');
		fwrite($file,$file_stream);
		fclose($file);
	}
}

?>